package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.SoulMapper;
import com.tanhua.dubbo.mappers.SoulQuestionMapper;
import com.tanhua.dubbo.mappers.SoulQuestionOptionMapper;
import com.tanhua.model.domain.Questionnaire;
import com.tanhua.model.domain.SoulQuestion;
import com.tanhua.model.domain.SoulQuestionOption;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SoulApiImpl implements SoulApi{
    @Autowired
    private SoulMapper soulMapper;

    @Autowired
    private SoulQuestionMapper soulQuestionMapper;

    @Autowired
    private SoulQuestionOptionMapper optionMapper;

    @Override
    public List<Questionnaire> QuestionnaireList() {
        LambdaQueryWrapper<Questionnaire> lqw=new LambdaQueryWrapper<>();
        lqw.orderByAsc(Questionnaire::getLevel);
        List<Questionnaire> questionnaireList = soulMapper.selectList(lqw);
        return questionnaireList;
    }

    @Override
    public List<SoulQuestion> questionByQuestionnaireId(Long id) {
        LambdaQueryWrapper<SoulQuestion> lqw=new LambdaQueryWrapper<>();
        lqw.eq(id!=null,SoulQuestion::getQuestionnaireId,id);
        lqw.orderByAsc(SoulQuestion::getId);
        List<SoulQuestion> questionList = soulQuestionMapper.selectList(lqw);
        return questionList;
    }

    @Override
    public List<SoulQuestionOption> optionByQuestionId(long id) {
        LambdaQueryWrapper<SoulQuestionOption> lqw=new LambdaQueryWrapper<>();
        lqw.eq(SoulQuestionOption::getQuestionId,id);
        lqw.orderByAsc(SoulQuestionOption::getId);
        List<SoulQuestionOption> optionList = optionMapper.selectList(lqw);
        return optionList;
    }
}
